package com.szh.zx.gaoDingJavaBook.yitu.one;

import java.util.ArrayList;
import java.util.List;

public class TestCollections {
	public static void main(String[] args) {
		List<Student22> list = new ArrayList<>();
		Student22 q = new Student22("q", "111");
		Student22 w = new Student22("q", "1111");
		list.add(q);
		System.out.println(list.contains(w));
	}
}

class Student22 {
	String name;
	String id;

	public Student22(String name, String id) {
		this.name = name;
		this.id = id;
	}

	@Override
	public String toString() {
		return "Student22{" +
				"name='" + name + '\'' +
				", id='" + id + '\'' +
				'}';
	}

	@Override
	public boolean equals(Object obj) {
//	 三个if
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Student22)) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		Student22 student1 = this;
		Student22 student2 = (Student22) obj;
		return student1.name.equals(student2.name) && student1.id.equals(student2.id
		);
	}
}